package com.education.controller.selectTestPeper;

import com.education.pojo.UserCollection;
import com.education.service.impl.SelectTestPeperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator on 2018/5/4.
 * 添加数据到我的收藏表
 */
@Controller
@CrossOrigin(origins = "*",maxAge = 3600)
public class insertUserCollectionController {
    @Autowired
    private SelectTestPeperImpl selectTestPeper;
    @RequestMapping("/insertUserCollection")
    @ResponseBody
    public int insertUserCollection(HttpServletRequest req){
        int tpid = Integer.parseInt(req.getParameter("tpId"));
        int uid = Integer.parseInt(req.getParameter("uId"));
        UserCollection userCollection = new UserCollection();
        userCollection.setTpId(tpid);
        userCollection.setuId(uid);
        List<UserCollection> listUserCollection = selectTestPeper.selectByUidAndTpid(uid,tpid);

        if(listUserCollection.size()>0){
            return 0;
        }else{
            int a = selectTestPeper.insertdatatoUserCollection(userCollection);

            return a;
        }


    }
}
